import { getTableInfo } from '../../api/scene'

const state = {
  tableData: [],
  total: '',
  index: ''
}

const mutations = {
  // 设置更新列表
  update_list (state, tableData) {
    state.tableData = tableData
  },
  // 总数
  list_count (state, total) {
    state.total = total
  }
}

const actions = {
  // 刷新列表
  updateTable (context, index) {
    return new Promise((resolve, reject) => {
      getTableInfo(index, 10)
        .then(res => {
          if (res.data.code === (200 || '200')) {
            context.commit('update_list', res.data.data.data)
            context.commit('list_count', res.data.data.count)
          }
          resolve(res)
        })
        .catch(err => {
          reject(err)
        })
    })
  }
}
export default {
  namespaced: true,
  actions,
  state,
  mutations
}
